home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / TIPS.SPP < prev   
Text File  |  1997-05-06  |  5KB  |  159 lines

  1. //--------------------------------------------------------------------------
  2. // Object Scripting
  3. // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
  4. //
  5. // TIPS.SPP: Evaluation Tips. When the debugger has a process loaded,
  6. //   evaluates the item under the cursor and displays the result in a
  7. //   mouse tip.  When there is no process loaded, show the name of the 
  8. //   buffer.
  9. //
  10. //--------------------------------------------------------------------------
  11.  
  12. // mark this module as being a library module
  13. library;
  14.  
  15. //
  16. // IDE imports.
  17. //
  18. import editor;
  19. import debugger;
  20. import IDE;
  21.  
  22. //
  23. // If debugging and we have a source file, evaluate the symbol under the
  24. // cursor when a mouse tip is "requested."
  25. //
  26. on editor:>MouseTipRequested(theView, line, col){
  27.   if (debugger.HasProcess) {
  28.     declare topView = editor.TopView;
  29.     declare curPos  = topView.Position;
  30.     declare curBlk  = topView.Block;
  31.  
  32.     // Get the block, or word under the cursor.
  33.     //
  34.     declare symbol;
  35.     if (curBlk.IsValid) {
  36.       symbol = curBlk.Text;
  37.     } else {
  38.       curPos.Save();
  39.       curPos.Move(line, col);
  40.       symbol = .GetCPPSymbol();
  41.       curPos.Restore();
  42.     }
  43.  
  44.     //
  45.     // Evaluate.
  46.     //
  47.     declare evaluation;
  48.     if (symbol != "") {
  49.       // Include ',r' so that members of structs and classes are named
  50.       evaluation = debugger.Evaluate(symbol + ",r");
  51.  
  52.       // Filter out empty and invalid expressions
  53.       declare String subStr(evaluation);
  54.       if(evaluation != "" && evaluation != "Expression syntax" &&
  55.          subStr.SubString(0, 9).Text != "Undefined" &&
  56.          subStr.SubString(0, 8).Text != "Improper"){
  57.           return symbol + ": " + evaluation;
  58.       }
  59.     } else {
  60.       return pass(theView, line, col);
  61.     }
  62.   }
  63.  
  64.   //  
  65.   // No process under debugger, if the mouse is resting over the currently 
  66.   // active EditView, do nothing (user can see view's description in the 
  67.   // View's title).  Otherwise, return the buffer's name and description.
  68.   //
  69.  
  70.   /*
  71.       customers found this behavior to be annoying, so it has been commented 
  72.       out.
  73.   if(editor.TopView != theView){
  74.      declare retVal = "";
  75.      declare eBuf = theView.Buffer;
  76.      if(eBuf.IsReadOnly)
  77.        retVal += "R";
  78.      if(eBuf.IsModified)
  79.        retVal += "*";
  80.      if(retVal != "")
  81.        retVal += "  ";
  82.      retVal += (eBuf.FullName + " (" + line + ", " + col + ")");
  83.  
  84.      return retVal;
  85.   }
  86.   */
  87.  
  88.   return pass(theView, line, col);
  89. }
  90.  
  91. on editor:>GetCPPSymbol(){
  92.    if(!initialized(.TopView)){
  93.       // no edit window exists, can't rip anything
  94.       return "";
  95.    }
  96.  
  97.    declare ep = .TopView.Position;
  98.    if (!(ep.IsWordCharacter || (ep.Character == '_') || (ep.Character == '.') ||
  99.       (ep.Character == '-') || (ep.Character == '>') || (ep.Character == ']') ||
  100.       (ep.Character == ']'))) {
  101.       return "";
  102.    }
  103.  
  104.    declare lhs = ep.RipText("0123456789_.->:[]", BACKWARD_RIP | INCLUDE_ALPHA_CHARS);
  105.    ep.MoveRelative(0, 1);
  106.  
  107.    declare rhs;
  108.  
  109.    // Only include brackets if one or more appear in the left hand side.
  110.    // This allows viewing the entire structure rather than the single
  111.    // element if the tip is requested to the left of '.' or '->'.
  112.    // A ':' is also included so that static class references are displayed
  113.    // with the "Class::" prefix if present.
  114.    declare String srch(lhs);
  115.  
  116.    if(srch.Contains("[]"))
  117.        rhs = ep.RipText("0123456789_.->:[]", INCLUDE_ALPHA_CHARS);
  118.    else
  119.        rhs = ep.RipText("0123456789_:", INCLUDE_ALPHA_CHARS);
  120.  
  121.    declare rv = lhs + rhs;
  122.  
  123.    // Derefernce operators (->) are okay in our return string, but minus (-) 
  124.    // and greater (>) than operators by themselves aren't.  Neither is a ':'.
  125.    declare String whole(rv);
  126.    if(whole.Contains(">-")){
  127.       // ensure that it contains only dereference operators.
  128.       for(declare i = 0; i < whole.Length; i++){
  129.          declare piece = whole.SubString(i);
  130.          if(piece.Character == '-'){
  131.             // next char must be a '>' or it is invalid!
  132.             piece = whole.SubString(++i);
  133.             if(piece.Character != '>'){
  134.                rv = whole.SubString(0, i - 1).Text;
  135.                break;
  136.             }
  137.          }else{
  138.             // if we see a '>' w/out a preceding '-', it is invalid
  139.             if(piece.Character == '>'){
  140.                rv = whole.SubString(0, i).Text;
  141.                break;
  142.             }else{
  143.                 // If ':', next char must be a ':' too or it is invalid
  144.                 if(piece.Character == ':'){
  145.                     piece = whole.SubString(++i);
  146.                     if(piece.Character != ':'){
  147.                        rv = whole.SubString(0, i - 1).Text;
  148.                        break;
  149.                     }
  150.                 }
  151.             }
  152.          }
  153.       }
  154.    }
  155.  
  156.    return rv;
  157. }
  158.  
  159.